#ifndef TITAN_H
#define TITAN_H

#include <QWidget>
#include <QTimer>
#include "format.h"
#include <QTcpSocket>
#include <QAbstractSocket>
#include <QKeyEvent>
#include <QEvent>

namespace Ui {
class Titan;
}

class Titan : public QWidget
{
    Q_OBJECT

public:
    explicit Titan(QWidget *parent = 0);
    ~Titan();


private slots:
    void on_connected();
    void on_read();
    void on_disconnected();
    void on_error(QAbstractSocket::SocketError _err);
    void on_check_timer();

    void on_loginBtn_clicked();

    void on_regBtn_clicked();

private:
    Ui::Titan *ui;
    Format* fmt;
    QTcpSocket* socket;
    QTimer* check_timer;

    QString recver;
    QString token;
    QString uid;

    QString name;
    QString passwd;
    int is_login = 0;

    int reconnect_flag = 0;
    void reconnect();

protected:
    void keyPressEvent(QKeyEvent * event);
    bool eventFilter(QObject *obj, QEvent *e);
};

#endif // TITAN_H
